require.config({
    paths: {
        'vue': '../encaptool/encvue',
        'iview': '../utiltool/iview/iview',
        'jquery': '../utiltool/jquery/jquery.min',
        'router': '../encaptool/encarouter',
        'axios': '../encaptool/encaxios'
    },
    shim: {
        iview: [
            'vue'
        ]
    }
})
require(['vue', 'iview', 'jquery', 'router', 'axios'], function(Vue, iview, $, Router, axios) {
    Vue.use(iview);
    new Vue({
        el: '#bourn_management',
        data() {
            return {
                bournid: '',
                completedCl: [{
                        title: '序号',
                        type: 'index',
                        align: 'center',
                        // width: 150
                    },
                    {
                        title: '配送点名称',
                        key: 'bournname',
                        align: 'center',
                        width: 400
                    },
                    {
                        title: '经度',
                        key: 'longitude',
                        align: 'center',
                        // width: 250
                    },
                    {
                        title: '纬度',
                        key: 'latitude',
                        align: 'center',
                        // width: 250
                    },
                    {
                        title: '累计送货次数（次）',
                        key: 'total',
                        align: 'center',
                        // width: 250
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        // width: 150,
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'large'
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.index);
                                        }
                                    }
                                }, '详情')
                            ]);
                        }
                    }
                ],
                // 全部信息
                wholeData: [],
                // 初始化信息总条数
                dataCount: 0,
                // 每页显示多少条
                pageSize: 50,
                // 每页信息
                historyData: [],
                loading: false
            };
        },
        methods: {
            getCompleted(index) {
                this.loading = true;
                var setting = {
                    method: 'GET',
                    url: '/YF/public/api/bournManage/' + index
                };
                axios.call(this, function(res) {
                    if (res.code === 0) {
                        this.historyData = res.data[1];
                        this.wholeData = res.data[0];
                        this.dataCount = res.data[3];
                        this.loading = false;
                    } else {

                    }
                }.bind(this), {
                    setting: setting
                });
            },
            // 分页代码吧= = 
            changePage(index) {
                this.getCompleted(index);
            },
            // 查询
            query() {
                this.loading = true;
                var setting = {
                    method: 'POST',
                    url: "/YF/public/api/queryBournManage/"
                };
                var data = {
                    bournid: this.bournid
                }
                axios.call(this, function(res) {
                    if (res.code === 0) {
                        this.historyData = res.data;
                        this.loading = false;
                    } else {
                        this.$Message.info('没有匹配数据');
                        this.loading = false;
                    }
                }.bind(this), {
                    setting: setting,
                    data: data
                });
            },
            // 显示全部
            selectAll() {
                this.getCompleted(1);
            },
            // 详情
            show(index) {
                this.$Modal.info({
                    title: '详细信息',
                    content: `<div style="font-size:13.5px;"><b>
                    配送点编号：${this.historyData[index]['bournid'] == null ? '暂无数据' : this.historyData[index]['bournid']}<br>
                    配送点名称：${this.historyData[index]['bournname'] == null ? '暂无数据' : this.historyData[index]['bournname']}<br>
                    经度：${this.historyData[index]['longitude'] == null ? '暂无数据' : this.historyData[index]['longitude']}<br>
                    纬度：${this.historyData[index]['latitude'] == null ? '暂无数据' : this.historyData[index]['latitude']}<br>
                    送货总次数:${this.historyData[index]['total'] == null ? '暂无数据' : this.historyData[index]['total']}<br>
                    </b></div>`
                })
            },
            // 导出csv
            exportData() {
                var today = new Date();
                var dateStr = today.getFullYear() + (today.getMonth() + 1).toString() +
                    today.getDate() + today.getHours() + today.getMinutes() + today.getSeconds();
                this.$refs.table.exportCsv({
                    filename: '配送点管理信息表' + dateStr,
                    columns: this.completedCl.filter((col, index) => index > 0 && index < 4),
                    data: this.wholeData
                });
            }
        },
        mounted() {
            this.getCompleted();
        }
    })
})